package com.secret.chain.secretchain.service.impl;

import com.secret.chain.secretchain.domain.entity.Problem;

import com.secret.chain.secretchain.mapper.ProblemMapper;
import com.secret.chain.secretchain.result.Result;
import com.secret.chain.secretchain.service.ProblemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
@Service
public class ProblemServiceImpl implements ProblemService {
    @Autowired
    private ProblemMapper problemMapper;
    @Override
    public Result queryByGroupId(Integer id) {
        Problem problem = problemMapper.queryByGroupId(id);
        return Result.success(problem);
    }

    @Override
    public Result queryByGroupAnswerUserId(Integer id) {
        Problem problem = problemMapper.queryByGroupAnswerUserId(id);
        return Result.success(problem);
    }

    @Override
    public Result queryByGroupAskUserId(Integer id) {
        Problem problem = problemMapper.queryByGroupAskUserId(id);
        return Result.success(problem);
    }

    @Override
    public Result save(Problem problem) {
        LocalDateTime now = LocalDateTime.now();
        problem.setStatus(1);
        problem.setCreateTime(now);
        problem.setUpdateTime(now);
        problemMapper.insert(problem);
        return Result.success();
    }

    @Override
    public Result delete(Integer id) {
        problemMapper.delete(id);
        return Result.success();
    }

    @Override
    public Result update(Problem problem) {
        LocalDateTime now = LocalDateTime.now();
        problem.setUpdateTime(now);
        problemMapper.update(problem);
        return Result.success();
    }
}
